from PySide2.QtCore import Qt
from PySide2.QtGui import QColor, QMouseEvent, QPalette
from PySide2.QtWidgets import (QWidget,)

class ColorWidget(QWidget):
    def __init__(self, color) -> None:
        super().__init__()

        self.setAutoFillBackground(True)

        self.color = QColor(color)
                
        palette = self.palette()
        palette.setColor(QPalette.Window, self.color)
        self.setPalette(palette)

    def mousePressEvent(self, event):
        super().mousePressEvent(event)

        palette = self.palette()

        r, g, b, _ = self.color.getRgb()
        color = QColor.fromRgb(r * 0.6, g * 0.6, b * 0.6)
        
        palette.setColor(QPalette.Window, color)
        self.setPalette(palette)

    def mouseReleaseEvent(self, event):
        super().mouseReleaseEvent(event)

        palette = self.palette()
        palette.setColor(QPalette.Window, self.color)
        self.setPalette(palette)